با استفاده از داده های زلزله ها در ایران و جهان به سوالات زیر پاسخ دهید.
کارهای اولیه
library(stringr)
library(readr)
library(dplyr)
library(tidyr)
library(highcharter)
library(ggplot2)
library(ggthemes)
library(ggmap)
library(gganimate)
library(plotly)
library(countrycode)
library(knitr)
theme_set(theme_minimal())
setwd('/Users/aminrakhsha/Documents/University/Term4 - 97spring/Data Analysis/HW/HW11')
sequake = read_rds("data/historical_web_data_26112015.rds")
disaster = read_delim("data/disaster.txt", "\t", escape_double = FALSE, trim_ws = TRUE)
iequake = read_rds("data/iran_earthquake.rds")
earthquakes = read_csv('data/worldwide.csv') %>% filter(type == 'earthquake')۱. با استفاده از داده های historical_web_data_26112015.rds و استفاده از نمودار پراکنش سه بعدی بسته plotly نمودار طول، عرض و عمق زلزله ها را رسم نمایید. علاوه بر آن بزرگی هر نقطه را برابر بزرگی زمین لرزه قرار دهید.
plot_ly(sequake, x = ~Longitude, y = ~Latitude, z = ~(-Depth), size = ~(10 * Magnitude)) %>%
add_markers() %>%
layout(scene = list(xaxis = list(title = 'Longitude'),
yaxis = list(title = 'Latitude'),
zaxis = list(title = 'Depth')))۲. پویانمایی سونامی های تاریخی را بر حسب شدت بر روی نقشه زمین رسم نمایید.(از داده زلزله های بزرگ استفاده نمایید.)
از پکیج gganimate استفاده میکنیم. نتیجه را در زیر میبینید:
tsunamies = disaster %>%
filter(FLAG_TSUNAMI == "Tsu")
# bbox <- c(left = -170, bottom = -60, right = 170, top = 80)
# worldMap = get_stamenmap(bbox, zoom = 3, maptype="toner-lite")
# saveRDS(worldMap, 'worldMap_toner_lite.rds')
# worldMap = readRDS('worldMap_toner_lite.rds')
# p = ggmap(worldMap, extent = "device") +
# geom_point(data = tsunamies, aes(x = LONGITUDE, y = LATITUDE, frame = YEAR, color = 'red'))
# p = gganimate(p, "q2_1.gif")
worldMap = map_data('world')
p = ggplot() +
geom_polygon(
data = worldMap,
aes(x = long, y = lat, group = group),
fill = "gray70",
color = 'gray80'
) +
coord_fixed() +
geom_point(
data = tsunamies,
aes(x = LONGITUDE, y = LATITUDE, frame = YEAR, color = EQ_PRIMARY)
) +
scale_color_gradient2(low = '#59f442', mid = '#f4f142', high = '#f22626', midpoint = 5.5) +
theme(axis.line=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank()) +
guides(color=guide_legend(title="Magnitude"))
# p
# p = gganimate(p, "q2_2.gif", ani.height = 350, ani.width = 800)